package com.yuanrui.auth.domain.service.impl;

import com.yuanrui.auth.basic.entity.AuthRole;
import com.yuanrui.auth.basic.service.AuthRoleService;
import com.yuanrui.auth.common.enums.IsDeletedFlagEnum;
import com.yuanrui.auth.domain.convert.AuthRoleConverter;
import com.yuanrui.auth.domain.entity.AuthRoleBO;
import com.yuanrui.auth.domain.service.AuthRoleDomainService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    @Override
    public Boolean addRole(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConverter.INSTANCE.convertToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        int insert = authRoleService.insert(authRole);
        return insert > 0;
    }

    @Override
    public Boolean updateRole(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConverter.INSTANCE.convertToEntity(authRoleBO);
        int update = authRoleService.update(authRole);
        return update > 0;
    }

    @Override
    public Boolean deleteRole(AuthRoleBO authRoleBO) {
        AuthRole authRole = new AuthRole();
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        authRole.setId(authRoleBO.getId());
        int update = authRoleService.update(authRole);
        return update > 0;
    }
}
